<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no" />
    <style type="text/css">
        body, html {width: 100%;height: 100%;margin:0;font-family:"微软雅黑";}
        #allmap{width:100%;height:500px;}
        p{margin-left:5px; font-size:14px;}
        label {
            /* display: inline-block; */
             max-width: 50px;
            /* margin-bottom: 5px; */
            /* font-weight: bold; */
        }
    </style>
    <script type="text/javascript" src="http://api.map.baidu.com/api?v=2.0&ak=ZPBWB5yWkiKVGNOblE9qp1zqq43zU8l6"></script>
    <title>添加多个标注点</title>
</head>
<body>
<div id="allmap"></div>
</body>
</html>
<script type="text/javascript">
    // 百度地图API功能
    var map = new BMap.Map("allmap");
    var point = new BMap.Point(104.06232,30.569874);
    map.centerAndZoom(point, 16);
    map.enableScrollWheelZoom(true);
    // 编写自定义函数,创建标注
    function addMarker(point,content){
        var marker = new BMap.Marker(point);
        map.addOverlay(marker);
        var label = new BMap.Label(content,{offset:new 	   BMap.Size(20,-10)});
        marker.setLabel(label);
    }
    // 随机向地图添加25个标注
    var bounds = map.getBounds();
    var sw = bounds.getSouthWest();
    var ne = bounds.getNorthEast();
    var lngSpan = Math.abs(sw.lng - ne.lng);
    var latSpan = Math.abs(ne.lat - sw.lat);
    var point1 = new BMap.Point(104.06232,30.569874);
    addMarker(point1,'活动地址');
    var point2 = new BMap.Point(104.05232,30.559874);
    addMarker(point2,'我的位置');
    alert('距离是：'+(map.getDistance(point1,point2)).toFixed(2)+' 米。');  //获取两点距离,保留小数点后两位
    var polyline = new BMap.Polyline([point1,point2], {strokeColor:"blue", strokeWeight:6, strokeOpacity:0.5});  //定义折线
    map.addOverlay(polyline);     //添加折线到地图上
</script>
